/*
 * @Author: xiaozhuang-c-language 3535851673@qq.com
 * @Date: 2025-06-05 22:55:26
 * @LastEditors: xiaozhuang-c-language 3535851673@qq.com
 * @LastEditTime: 2025-06-06 22:17:36
 * @FilePath: /zhuang/http-v1/request.cc
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include<iostream>
#include<string>
#include<regex>
using namespace std;

int main()
{
   string exp = "GET http://42.194.139.95:8082/login HTTP/1.1";
   //.匹配/n/r之外的任何单个字符
   //*匹配前面的子表达式零次或多次
   std::regex e("(GET|HEAD|POST|DELETE) ([^?]*)(?:\\?(.*))? (HTTP/1\\.[01])(?:\n|\r\n)?");
   //(GET|HEAD|POST|DELETE) 表示匹配并提取其中任意一个字符串
   //[^?*] [^?]匹配非问号
   // \\?(.*)表示匹配原始的？字符之后的任意字符0次或多次，直到遇到空格
   // HTTP/1\\.[01] 表示匹配以HTTP/1.开始

   std::smatch matches;
   //
  bool ret = std::regex_match(exp,matches,e);
  if(ret == false) //匹配失败
  {
   cerr << "match error" << endl;
    exit(1);
  }
  for(auto& s : matches)
      cout << s << endl;
   return 0;
}